package com.imooc;

import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

@SpringBootApplication
public class GirlApplication extends WebMvcConfigurerAdapter  {

	public static void main(String[] args) {
		SpringApplication.run(GirlApplication.class, args);
	}

	@Override
	public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
		super.configureMessageConverters(converters);

		/*
			1. 首先需要定义一个 Converter 转换对象
			2. 添加fastjson的配置信息  如是否需要格式化返回	的fastjson的数值信息
			3. 在Converter中配置信息
			4. 将Converter添加到 converters 中
		 *
		 */
		FastJsonHttpMessageConverter fastConverter  =  new FastJsonHttpMessageConverter();
		FastJsonConfig fastJsonConfig = new FastJsonConfig();

		fastJsonConfig.setSerializerFeatures(
				SerializerFeature.PrettyFormat
		);

		fastConverter.setFastJsonConfig(fastJsonConfig);
		converters.add(fastConverter);

	}
}
